package org.ftc.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.ftc.dao.CommitteeDao;
import org.ftc.domain.Committee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommitteeService {

	@Autowired
	CommitteeDao committeeDao;
	@Autowired
	private UsersService usersService;

	public Committee load(String id) {
		return committeeDao.load(id);
	}

	public Committee get(String id) {
		return committeeDao.get(id);
	}

	public synchronized boolean save(Committee entity) {
		return committeeDao.save(entity);
	}

	public synchronized boolean saveOrUpdate(Committee entity) {
		return committeeDao.saveOrUpdate(entity);
	}

	public synchronized boolean update(Committee entity) {
		return committeeDao.update(entity);
	}

	public synchronized boolean delete(Committee entity) {
		return committeeDao.delete(entity);
	}

	public synchronized boolean delete(String id) {
		return committeeDao.delete(id);
	}

	public List<Committee> findAll() {
		return committeeDao.findAll();
	}

	public List<Committee> findCkd() {
		return committeeDao.findCkd();
	}
	
	public List<Committee> findByCode(String code) {
		return committeeDao.findByCode(code);
	}

	public long countAll() {
		return committeeDao.countAll();
	}
	
	public String committeesName(String ids) {
		String name = "";
		if(StringUtils.isNotBlank(ids)&&StringUtils.split(ids, ",").length!=0){
			List<String> nameList = new ArrayList<>();
			for(final String id : StringUtils.split(ids, ",") ){
				Committee committee = this.get(id);
				if(committee==null){
					 continue;
				}
				nameList.add(committee.getName());
			}
			name = StringUtils.join(nameList, "、");
		}
		return name;
	}

}
